# -*- coding: utf-8 -*-
__author__ = 'sunnychou'
__date__ = '2019/7/5 19:30'

'''
产品经理excel报表自动化生成模块
'''

import xlsxwriter
from common.excel_helper import XLSXBooker

def create_pm_report_header(workbooker):


    sheet_name = '产品经理日常考核报表-2019-05月份'
    workbooker.add_worksheet(sheet_name)

   #设置列宽度
    workbooker.set_unit_column_width('A:B', 8)
    workbooker.set_unit_column_width('D:D',8)
    workbooker.set_unit_column_width('C:X', 6)

    # line2
    workbooker.set_unit_row_height(1, 20)
    workbooker.add_worksheet_merge_range(range_column='A2:W2', content='2019年5月份产品经理日常工作绩效考核评估表',
                                         font_size=20, border=1)

    # line 3
    workbooker.set_unit_row_height(2, 30)
    workbooker.add_worksheet_merge_range(range_column='A3:O3', content='所属部门: 飞五科技产品部',
                                         font_size=20, border=1, align='left')

    workbooker.add_worksheet_merge_range(range_column='P3:Q3', content= '统计时间段:', font_size=12,border=1,align='left')

    workbooker.add_worksheet_merge_range(range_column='R3:T3', content= '2019-05-01', font_size=12,border=1,align='center',
                                         fg_color='yellow')

    workbooker.add_worksheet_merge_range('U3:W3', '2019-05-31', font_size=12, border=1, align='center',
                                         fg_color='yellow')

    #line 4
    workbooker.set_unit_row_height(3, 30)
    workbooker.add_worksheet_merge_range('A4:W4', '第一部分：年度工作结果类指标', font_size=8, border=1, align='center',
                                         fg_color='#D0D0D0')


    #line 5
    workbooker.set_unit_row_height(4, 30)

    workbooker.add_worksheet_merge_range('A5:A8', '员工姓名',  font_size=10, border=1, align='center')

    workbooker.add_worksheet_merge_range('B5:D7', '客户跟踪计划报告\r\n产品指导积分', font_size=10, border=1, align='center')

    workbooker.add_worksheet_merge_range('E5:G7', '项目跟踪管理', font_size=10, border=1, align='center')

    workbooker.add_worksheet_merge_range('H5:J7', '管理跟踪', font_size=10, border=1, align='center')

    workbooker.add_worksheet_merge_range('K5:N5', '产品管理', font_size=10, border=1, align='center')


    #line 6
    workbooker.set_unit_row_height(5, 30)
    workbooker.add_worksheet_merge_range('K6:L6', '加分项', font_size=10, border=1, align='center')

    workbooker.add_worksheet_merge_range('M6:N6', '减分项', font_size=10, border=1, align='center')


    #line 7
    workbooker.set_unit_row_height(6, 30)
    workbooker.add_worksheet_merge_range('K7:L7', '1、产品行业管理\r\n2、竞争管理\r\n3、产品论坛 ',
                                         font_size=8, border=1, align='center')

    workbooker.add_worksheet_merge_range('M7:N7', '1、产品信息管理\n2、产品商务管理\n3、样品管理\n4、项目产品管理\n '
                                   '5、备货管理\n6、项目管理\n7、供应商管理 ',
                                         font_size=8, border=1, align='center')


    #line 5 extra
    workbooker.add_worksheet_merge_range('O5:P7', '调剂得分',
                                         font_size=8, border=1, align='center')

    workbooker.add_worksheet_merge_range('Q5:Q8', '积分合计',
                                         font_size=8, border=1, align='center')

    workbooker.add_worksheet_merge_range('R5:S8', '积分平均分',
                                         font_size=8, border=1, align='center')

    workbooker.add_worksheet_merge_range('T5:U8', '绩效工资\r\n等级评定',
                                         font_size=8, border=1, align='center')

    workbooker.add_worksheet_merge_range('V5:W8', '本月绩效\r\n工资系数',
                                         font_size=8, border=1, align='center')

    workbooker.set_unit_row_height(7, 30)

    workbooker.add_worksheet_merge_range('B8:C8', '统计积分',
                                         font_size=8, border=1, align='center', color='red')

    workbooker.add_worksheet_unit('D8', '比例值',
                                         font_size=8, border=1, align='center')


    workbooker.add_worksheet_merge_range('E8:F8', '统计积分',
                                         font_size=8, border=1, align='center', color='red')


    workbooker.add_worksheet_unit('G8', '比例值',
                                         font_size=8, border=1, align='center')

    workbooker.add_worksheet_merge_range('H8:I8', '报告积分',
                                         font_size=8, border=1, align='center', color='red')

    workbooker.add_worksheet_unit('J8', '比例值',
                                  font_size=8, border=1, align='center')

    workbooker.add_worksheet_merge_range('K8:L8', '分值',
                                         font_size=8, border=1, align='center', color='red')

    workbooker.add_worksheet_merge_range('M8:N8', '分值',
                                         font_size=8, border=1, align='center', color='red')

    workbooker.add_worksheet_unit('O8', '分值',
                                         font_size=8, border=1, align='center', color='red')

    workbooker.add_worksheet_unit('P8', '分值',
                                  font_size=8, border=1, align='center', color='red')


    return workbooker



def create_pm_data_report_footer(workbooker):
    # line 14
    workbooker.set_unit_row_height(13, 30)

    workbooker.add_worksheet_unit('A14', '总分',
                                         font_size=8, border=1, align='center', fg_color='yellow')

    workbooker.add_worksheet_merge_range('B14:C14', '40',
                                         font_size=8, border=1, align='center', fg_color='yellow')

    workbooker.add_worksheet_merge_range('E14:F14', '30',
                                         font_size=8, border=1, align='center', fg_color='yellow')

    workbooker.add_worksheet_merge_range('H14:I14', '30',
                                         font_size=8, border=1, align='center', fg_color='yellow')


    #（2）第二部分：调剂理由
    workbooker.set_unit_row_height(14, 20)
    workbooker.add_worksheet_merge_range('A15:W15', '第二部分：调剂理由',
                                         font_size=8, border=1, align='center', fg_color='#D0D0D0')

    workbooker.set_unit_row_height(15, 100)
    workbooker.add_worksheet_merge_range('A16:W16', '',
                                         font_size=8, border=1, align='center')


    # （3）第三部分：签字确认
    workbooker.set_unit_row_height(16, 20)
    workbooker.add_worksheet_merge_range('A17:W17', '第三部分：签字确认',
                                         font_size=8, border=1, fg_color='#D0D0D0')


    #line 18
    workbooker.set_unit_row_height(17, 20)
    workbooker.add_worksheet_merge_range('A18:L18', '考核总计分值:',
                                         font_size=8, border=1)

    #line 19
    workbooker.set_unit_row_height(18, 20)
    workbooker.add_worksheet_merge_range('A19:L19', '被考核者签字\签字日期:',
                                         font_size=8, border=1)

    #line 20
    workbooker.set_unit_row_height(19, 20)
    workbooker.add_worksheet_merge_range('A20:L20', '考核者签字\签字日期:',
                                         font_size=8, border=1)

    #line 18
    workbooker.add_worksheet_merge_range('M18:Q18', '被考核者自评',
                                         font_size=8, border=1)

    workbooker.add_worksheet_merge_range('M19:Q20', '',
                                         font_size=8, border=1)

    workbooker.add_worksheet_merge_range('R18:W18', '上级领导评价',
                                         font_size=8, border=1)

    workbooker.add_worksheet_merge_range('R19:W20', '',
                                         font_size=8, border=1)

    #line 21
    workbooker.set_unit_row_height(20, 20)
    workbooker.add_worksheet_merge_range('A21:W21', '考核指标统计说明',
                                         font_size=8, border=1,fg_color='#D0D0D0')


    workbooker.set_unit_row_height(21, 100)
    workbooker.add_worksheet_merge_range('A22:W22','')

    workbooker.set_unit_row_height(23, 40)
    workbooker.add_worksheet_merge_range('A24:N24', '文件批准人:',
                                         font_size=8, border=1, align='left')

    workbooker.add_worksheet_merge_range('P24:W24', '日期:',
                                         font_size=8, border=1, align='left')

    return  workbooker




def create_pm_data_report(xlsx_name, doc_code):
    # 生成头部
    workbooker = XLSXBooker(xlsx_name, doc_code)
    create_pm_report_header(workbooker)

    # 生成尾部
    workbooker = create_pm_data_report_footer(workbooker)

    return workbooker



if  __name__ == "__main__":
    xslx_name = '产品经理日常考核报表_v2.xlsx'
    doc_code = '产品存档文件编号：  CP_003'
    create_pm_data_report(xslx_name, doc_code)



